from matplotlib import rcParams
import matplotlib.pyplot as plt
from System.util import *
import pickle


fontdict=dict(fontsize=14,
    color='black',
    family='Times New Roman',
    weight='light'
    )


config = {
        "font.family": 'Times New Roman',
        "font.size": 14,
        "mathtext.fontset": 'stix',
        # "font.serif": ['SimSun'],
    }

rcParams.update(config)


def load_data(file_path):
    with open(f"{file_path}", 'rb') as f:
        x_math_list,y_math_list,x_sim_list,y_sim_list=pickle.load(f)
    return x_math_list,y_math_list,x_sim_list,y_sim_list

specific_dir="vs_v5"
path="F:/桌面/博士课题研究/IC2Eposter/exp_data/"




fig, ax = plt.subplots(2,2,figsize=(7,5))

file_name_num_server=get_specific_file_name_by_spec_str_list(path+specific_dir,["num_server"])
x_math_list,y_math_list,x_sim_list,y_sim_list=load_data(path+specific_dir+"/"+file_name_num_server)
ax[0][0].plot(x_math_list,y_math_list,color="tab:red",label="Theory value")
ax[0][0].scatter(x_sim_list,y_sim_list,color="tab:brown",label="Simulation value")
ax[0][0].set_xlabel("Microservice number\n(a)")
ax[0][0].set_ylabel("Reliability")




file_name_num_server=get_specific_file_name_by_spec_str_list(path+specific_dir,["lamda_out"])
x_math_list,y_math_list,x_sim_list,y_sim_list=load_data(path+specific_dir+"/"+file_name_num_server)
ax[0][1].plot(x_math_list,y_math_list)
ax[0][1].scatter(x_sim_list,y_sim_list)
ax[0][1].set_xlabel("Request come interval\n(b)")
ax[0][1].set_ylabel("Reliability")

file_name_num_server=get_specific_file_name_by_spec_str_list(path+specific_dir,["lamda_norm"])
x_math_list,y_math_list,x_sim_list,y_sim_list=load_data(path+specific_dir+"/"+file_name_num_server)
ax[1][0].plot(x_math_list,y_math_list)
ax[1][0].scatter(x_sim_list,y_sim_list)
ax[1][0].set_xlabel("Microservice normal time\n(c)")
ax[1][0].set_ylabel("Reliability")

file_name_num_server=get_specific_file_name_by_spec_str_list(path+specific_dir,["lamda_error"])
x_math_list,y_math_list,x_sim_list,y_sim_list=load_data(path+specific_dir+"/"+file_name_num_server)
ax[1][1].plot(x_math_list,y_math_list)
ax[1][1].scatter(x_sim_list,y_sim_list)
ax[1][1].set_xlabel("Microservice error time\n(d)")
ax[1][1].set_ylabel("Reliability")

ax[0][0].legend(loc="center", bbox_to_anchor=(1.1, 1.1), ncol=2,fontsize=12)
plt.subplots_adjust(left=0.10, bottom=0.14, right=0.99, top=0.93, wspace=0.3, hspace=0.5)
plt.savefig(path+specific_dir+"/compare_math_vs_sim.jpg",dpi=300)

plt.show()